package com.yhg.context.web;


import com.yhg.common.utils.R;
import com.yhg.context.entity.BlType;
import com.yhg.context.service.BlTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 帖子类型表 前端控制器
 * </p>
 *
 * @author 凌月青缃
 * @since 2021-01-21
 */
@RestController
@RequestMapping("/context/type")
@CrossOrigin
public class BlTypeController {

    @Autowired
    BlTypeService typeService;

    //map集合，将typeid与name封装成map，用以前端最小化性能损耗
    @GetMapping("getTypeMap")
    public R getTypeMap(){
        Map<String, Object> typeMap = typeService.getTypeMap();
        return R.ok().data(typeMap);
    }


    @GetMapping("list")
    public R list(){
        List<BlType> typeList = typeService.listAll();
        return R.ok().data("typeList",typeList);
    }

    @GetMapping("getNameById/{id}")
    public R getNameById(@PathVariable("id")Integer id){
        BlType byId = typeService.getById(id);
        return R.ok().data("typeName",byId.getTypeName());

    }

}

